package mbu;

import static org.junit.Assert.assertEquals;
import junit.framework.Assert;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * This test simply verifies that StairShooter can beat Tracker.
 * 
 * @author Michael Uranaka
 */
public class TestVersusTracker extends RobotTestBed {

  /**
   * Specifies that Tracker and StairShooter are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Tracker,mbu.StairShooter";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that StairShooter has won at least 2 rounds against Tracker.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is StairShooter.
    BattleResults stairShooterResults = battleResults[1];
    String robotName = stairShooterResults.getTeamLeaderName();
    assertEquals("Check that results[1] is StairShooter", robotName, "mbu.StairShooter*");
    // Check to make sure StairShooter won at least 20%.
    int won = stairShooterResults.getFirsts();
    Assert.assertTrue(won > 2);
  }

}
